﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Training.Domain;

namespace Training.Presentation
{
    public enum StartMenuEnum
    {
        ListPersons = 1,
        CreatePerson = 2,
        Exit = 0
    }

    public enum ListMenuEnum
    {
        AllPersons = 1,
        //PagedPersons = 2,
        RebootApplication = 9,
        Exit = 0
    }

    public enum EditItemMenu
    {
        EditName = 1,
        EditSurname = 2,
        EditDateOfBirth = 3,
        EditSalary = 4,
        RemoveItem = 9,
        Exit = 0
    }

    public static class Menu
    {
        public static StartMenuEnum StartMenu()
        {
            Console.WriteLine(string.Format("Choose an option:"));
            Console.WriteLine(string.Format("1- List Persons"));
            Console.WriteLine(string.Format("2- Create Person"));
            Console.WriteLine(string.Format("0- Exit"));

            return (StartMenuEnum)CheckIfItemExits(typeof(StartMenuEnum), Validation.ValidateReadLineInteger());
        }

        public static ListMenuEnum ListPersonsMenu()
        {
            Console.WriteLine(string.Format("Choose an option:"));
            Console.WriteLine(string.Format("1- List All Persons"));
            //Console.WriteLine(string.Format("2- List Paged Person"));
            Console.WriteLine(string.Format("9- Reboot Application"));

            return (ListMenuEnum)CheckIfItemExits(typeof(ListMenuEnum), Validation.ValidateReadLineInteger());
        }

        public static EditItemMenu EditItemMenu(Person person)
        {
            Console.WriteLine(string.Format("VAT: {0}", person.Vat));
            Console.WriteLine(string.Format("1- Name: {0}", person.Name));
            Console.WriteLine(string.Format("2- Surname: {0}", person.Surname));
            Console.WriteLine(string.Format("3- Date Of Birth: {0}", person.Birthdate));
            Console.WriteLine(string.Format("4- Salary: {0}", person.Salary));
            Console.WriteLine();
            Console.WriteLine(string.Format("9- Remove"));
            Console.WriteLine(string.Format("0- Exit"));

            Console.WriteLine("Select a row to make actions. Write Number and push Enter Key");

            return (EditItemMenu)CheckIfItemExits(typeof(EditItemMenu), Validation.ValidateReadLineInteger());
        }

        private static int CheckIfItemExits(Type typeOfMenu, int itemId)
        {
            if (!Enum.IsDefined(typeOfMenu, itemId))
            {
                Console.WriteLine("Enter right menu idetifier");
                var ret = CheckIfItemExits(typeOfMenu, Validation.ValidateReadLineInteger());
                return ret;
            }

            return itemId;
        }
    }
}
